/* Includes ------------------------------------------------------------------*/
#include "nfile.h"
#include "easyflash.h"
/* typedef -------------------------------------------------------------------*/
/* define --------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
int EasyFlash_Open(struct FileObj *file, int oflag, va_list args);
size_t EasyFlash_Write(struct FileObj *file, void *buf, size_t count);
size_t EasyFlash_Read(struct FileObj *file, void *buf, size_t count);
int EasyFlash_Lseek(struct FileObj *file, int offset, int whence);
int EasyFlash_Close(struct FileObj *file);
int EasyFlash_Fstat(struct FileObj *file, struct stat *status);


struct FcntlOperation easyflashOps = {
    .open = EasyFlash_Open,
    .write = EasyFlash_Write,
    .read = EasyFlash_Read,
    .lseek = EasyFlash_Lseek,
    .close = EasyFlash_Close,
    .fstat = EasyFlash_Fstat
};
/* function prototypes -------------------------------------------------------*/
/* functions -----------------------------------------------------------------*/
/*********************************************************************************************

 * file open

**********************************************************************************************/
int EasyFlash_Open(struct FileObj *file, int oflag, va_list args)
{   
	return 0;
}
/*********************************************************************************************

 * file write

**********************************************************************************************/
size_t EasyFlash_Write(struct FileObj *file, void *buf, size_t count)
{   
	if(ef_set_env_blob(file->path, buf, count) == EF_NO_ERR)
	{	return count;	}
	else
	{	return 0;	}
}
/*********************************************************************************************

 * file read

**********************************************************************************************/
size_t EasyFlash_Read(struct FileObj *file, void *buf, size_t count)
{   
	uint32_t countRead = 0;
	if(ef_get_env_blob(file->path, buf, count, &countRead) > 0)
	{	return count;	}
	else
	{	return 0;	}
	
}
/*********************************************************************************************

 * file lseek

**********************************************************************************************/
int EasyFlash_Lseek(struct FileObj *file, int offset, int whence)
{
	return 0;
}
/*********************************************************************************************

 * file close

**********************************************************************************************/
int EasyFlash_Close(struct FileObj *file)
{
	return 0;
}
/*********************************************************************************************

 * file status

**********************************************************************************************/
int EasyFlash_Fstat(struct FileObj *file, struct stat *status)
{
	return 0;
}

FILE_DRIVER_INSTALL(easyflash);
